package com.itheima.controller;


import com.itheima.pojo.CheckItem;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.R;
import com.itheima.service.CheckItemService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/checkitem")
public class CheckitemController {

    @Autowired
    private CheckItemService service;



    @PostMapping("/findPage")
    public Map<String,Object> findPage(@RequestBody PageBean pageBean){
        Map page = service.findPage(pageBean);
        return page;
    }

    @PostMapping("/add")
    public R add(@RequestBody CheckItem checkItem ){

        if (checkItem != null) {
            int i = service.add(checkItem);
            return new R(checkItem,true,"成功");
        }
        return null;
    }

    @GetMapping("/delete")
    public R delete(Long id){
        if (id != null){
            service.deleteByid(id);
            return new R(null,true,"删除成功");
        }
        return null;
    }

    @PostMapping("/edit")
    public R findById(@RequestBody CheckItem checkItem){
        if (checkItem != null){
            service.update(checkItem);
        }
        return null;
    }

    @GetMapping("/findById")
    public R find(@RequestParam Long id){

        if (id != null) {
            CheckItem checkItem = service.findById(id);
            return new R(checkItem,true,null);
        }
        return null;
    }
}
